// video add controller
var app = angular.module('app');

app.controller('bookAddFromNetCtrl',
    ['$scope', '$state', '$translate', '$window',
        'uploadFileService', 'confirmDialogService', 'bookService', 'status', 'toasterService',
        function ($scope, $state, $translate, $window, uploadFileService, confirmDialogService,
                  bookService, status, toasterService) {

            $scope.status = status;


            $scope.search = function (query) {
                if (!query || !query.isbn) {
                    return;
                }
                bookService.searchByIsbn(query.isbn)
                    .then(function (data) {
                        $scope.result = data;
                        if ($scope.result.exist) {
                            toasterService.pop('info', null, $translate.instant('strings.book.add.exist'));
                        } else {
                            toasterService.pop('success', null, $translate.instant('strings.book.add.success'));
                        }
                        $scope.book = $scope.result.book;
                    });
            };
            $scope.close = function () {
                $window.history.back();
            };
        }]);